#ifndef _TEXTPAGE_H
#define _TEXTPAGE_H

#include <webkit/webkit.h>
#include <amanita/aString.h>
#include "Main.h"
#include "Page.h"
#include "occult/Occult.h"



class TextPage : public Page {
private:
	static symbol_t history[1024];
	static int history_len;
	static int history_index;

	struct {
		GtkWidget *webview;
	} gtk;

	int status;
	uint64_t id;
	symbol_t symbol;

	static void webview_hover_event_callback(WebKitWebView *webview,gchar *title,gchar *uri,gpointer data);
	static gboolean webview_navigation_decision_event_callback(WebKitWebView *webview,WebKitWebFrame *frame,WebKitNetworkRequest *request,
																	WebKitWebNavigationAction *action,WebKitWebPolicyDecision *decision,gpointer data);
//	static gboolean webview_navigation_event_callback(WebKitWebView *webview,WebKitWebFrame *frame,WebKitNetworkRequest *request,gpointer data);
	static void go_back_callback(GtkWidget *widget,gpointer data);
	static void go_forward_callback(GtkWidget *widget,gpointer data);
	static void find_callback(GtkWidget *widget,gpointer data);
	static void help_callback(GtkWidget *widget,gpointer data);

	void init();

	void addToHistory(symbol_t s);

	void writeTitle(aString &title,Symbol &s,symbol_t *refs=0);
	void writeHead(aString &html,aString &title);
	bool writeArticle(aString &html,aString &title,Symbol &s);
	void writeReferences(aString &html,Symbol &s,symbol_t *n);
	void writeFoot(aString &html);

public:
	TextPage();
	TextPage(symbol_t s);
	TextPage(const char *uri);
	~TextPage();

	static void clearHistory();
	static void loadHistory();
	static void saveHistory();

	void goBack();
	void goForward();

	void navigate(const char *uri);
	void setDocument(symbol_t s);
	void setText(const char *txt,const char *t);
};


#endif /* _TEXTPAGE_H */


